package com.wxm.jwt.service.util;

import com.wxm.jwt.service.properties.JWTAuthService;
import com.wxm.jwt.service.properties.JWTByteAuthService;
import com.wxm.jwt.service.properties.JWTFileAuthService;
import lombok.Data;
import java.io.File;

/**
 * <p>
 *      服务端认证配置构建工厂
 * </p>
 *
 * @author: wxm
 * @Date: 2021/10/6
 */
@Data
public class JWTAuthServiceFactory {
    private JWTAuthServiceFactory(){}

    /**
     * 构建JWTAuthService
     * @param clazz 类型
     * @param pubObj 公钥参数
     * @param priObj 私钥参数
     * @param expireSecond 过期秒数
     * @return JWTAuthService
     */
    public static JWTAuthService buildJWTAuthClient(Class<? extends JWTAuthService> clazz, Object pubObj, Object priObj, Integer expireSecond){
        if (clazz.equals(JWTByteAuthService.class)){
            return new JWTByteAuthService((byte[]) pubObj,(byte[]) priObj,expireSecond);
        }else if (clazz.equals(JWTFileAuthService.class)){
            return new JWTFileAuthService((File) pubObj,(File) priObj,expireSecond);
        }
        return null;
    }
}
